<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=s, initial-scale=1.0">
    <title>Document</title>
    <!-- 1.导入框架 -->
    <script src="./echarts.js"></script>
    <script src="../admin/libs/http.js"></script>
</head>

<body>
    <!-- 2.准备html -->
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 900px;height:400px;"></div>

    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));



        const xhr = new XMLHttpRequest();
        xhr.open('get', BigNew.articleNewCount);
        xhr.setRequestHeader('Authorization', localStorage.getItem('token'));
        xhr.send();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                const backData = JSON.parse(xhr.response)
                console.log(backData);
                if (backData.code === 200) {
                    let data = [], date = [];
                    backData.date.forEach(element => {
                        date.push(element.date);
                        data.push(element.count);
                    });
                    loadLineEcharts(date, data)
                }
            }
        }

        function loadLineEcharts(date, data) {
            option = {
                tooltip: {
                    trigger: 'axis',
                    position: function (pt) {
                        return [pt[0], '10%'];
                    }
                },
                legend: {
                    data: ['新增文章'],
                    top: '30'

                },
                title: {
                    left: 'center',
                    text: '月新增文章数',
                },
                toolbox: {
                    show: true,
                    feature: {
                        dataZoom: {
                            yAxisIndex: 'none'
                        },
                        dataView: { readOnly: false },
                        magicType: { type: ['line', 'bar'] },
                        restore: {},
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: date,
                    name: '日'
                },
                yAxis: {
                    type: 'value',
                    boundaryGap: [0, '100%'],
                },

                series: [
                    {
                        name: '新增文章',
                        type: 'line',
                        smooth: true,
                        // symbol: 'none',
                        sampling: 'average',
                        itemStyle: {
                            color: 'rgb(240, 143, 57)'
                        },
                        areaStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: 'rgba(255,136,0,0.39)'
                            }, {
                                offset: .34,
                                color: 'rgba(255,180,0,0.25)'
                            },
                            {
                                offset: 1,
                                color: 'rgba(255,222,0,0.00)'
                            }])
                        },
                        data: data
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }



    </script>
</body>

</html>